#!/usr/bin/perl

use strict;
use lib '.';

use RDF::Redland;
use Swignition::DataModel::Model;
use Swignition::DataModel::Graph;
use Swignition::DataModel::Triple;
use Swignition::DataModel::BlankNode;
use Swignition::DataModel::Resource;
use Swignition::DataModel::Literal;
use Swignition::DataModel::XMLLiteral;

use Data::Dumper;
my $i = 0;

my $model  = Swignition::DataModel::Model->new;
my $graph  = Swignition::DataModel::Graph->new($model);
my $graph2 = Swignition::DataModel::Graph->new($model);

$graph->quick_rrl('http://tobyinkster.co.uk/~tobyink/#', 
	'http://xmlns.com/foaf/0.1/name',
	'Toby Inkster',
	undef,
	'en_GB');
$graph->quick_rrr('http://dbpedia.org/resource/Toby_Inkster', 
	'http://xmlns.com/foaf/0.1/page',
	'http://tobyinkster.co.uk');
$graph->quick_rrl('_:n1', 'http://xmlns.com/foaf/0.1/name', 'Freddy', undef, 'en');
$graph->quick_rrl('_:n1', 'http://xmlns.com/foaf/0.1/name', 'Frederick', undef, 'de');

$graph->lookup_node('http://dbpedia.org/resource/Toby_Inkster')->merge_with(
	$graph->lookup_node('http://tobyinkster.co.uk/~tobyink/#'));

my $triple = $graph2->quick_rrl('_:n1', 'http://xmlns.com/foaf/0.1/name', 'Fred', undef, 'en');
$graph2->quick_rrr($triple, 'http://xmlns.com/foaf/0.1/maker', '_:Fred');

my $rl = $model->combined_graph->as_redland;
my $serializer = RDF::Redland::Serializer->new("ntriples");
print $serializer->serialize_model_to_string(RDF::Redland::URI->new('http://dbpedia.org/resource/'), $rl);

# print Dumper([$graph->lookup_node('http://tobyinkster.co.uk/~tobyink/#')->uris]);


__END__

my $me       = Swignition::DataModel::Resource->new($model,
		'http://tobyinkster.co.uk/~tobyink/#');
my $me2      = Swignition::DataModel::Resource->new($model,
		'http://dbpedia.org/resource/Toby_Inkster');
my $foafname = Swignition::DataModel::Resource->new($model,
		'http://xmlns.com/foaf/0.1/name');
my $toby     = Swignition::DataModel::Literal->new($model,
		'Toby Inkster', 'en');
my $foafpage = Swignition::DataModel::Resource->new($model,
		'http://xmlns.com/foaf/0.1/page');
my $ticu     = Swignition::DataModel::Resource->new($model,
		'http://tobyinkster.co.uk');


my $graph = $model->combined_graph;
$graph->quick($me,  $foafname, $toby);
$graph->quick($me2, $foafpage, $ticu);
$me->merge_with($me2);

print Dumper($graph->as_json);
print Dumper($model);

#printf("%s\n", $foafname->uri);
#printf("%s\n", $toby->string);
#print scalar(@{$foafname->subject_of});

